#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main()
{
    int fd;
    fd = open("./output.txt", O_RDWR);
    printf("open file success fd = %o\n", fd);

    char buf_read[6] = {0};
    int res_read = read(fd, buf_read, 5);
    printf("read %d bytes,content is %s\n", res_read, buf_read);

    char buf_write[] = "ABCDE";
    int res_write = write(fd, buf_write, 5);
    printf("write %d bytes\n", res_write);

    char buf_read1[6] = {0};
    int res_read1 = read(fd, buf_read1, 5);
    printf("read %d bytes,content is %s\n", res_read1, buf_read1);

    char buf_write1[] = "1234567890";
    int res_write1 = write(fd, buf_write1, 10);
    printf("write %d bytes\n", res_write1);

    // 同一个文件，fd可以重复使用 fd不变的时候 读取还是写入光标都会自动往后便宜

    close(fd);
    return 0;
}